<?phpnamespace app\common\model\food;use addons\food\library\Order as Ev;use app\common\model\Setting as SettingModel;use app\common\model\User as UserModel;use app\common\model\Record as RecordModel;use hema\delivery\Driver as Delivery;use hema\wechat\Driver as Wechat;use hema\wechat\Pay as WxPay;use app\common\model\Applet;use think\facade\Db;use think\facade\Cache;/** * 订单模型 */class Order extends BaseModel{    // 定义表名    protected $name = 'food_order';    // 定义主键    protected $pk = 'order_id';    // 追加字段    protected $append = [        'user'        ];	    /**     * 模型基类初始化     */    public static function init()    {        parent::init();        (new Ev((int)self::$applet_id))->listen();    }    /**     * 订单商品列表     */    public function goods()    {        return $this->hasMany('app\\common\\model\\food\\OrderGoods','order_id');    }    /**     * 关联订单收货地址表     */    public function address()    {        return $this->hasOne('app\\common\\model\\food\\OrderAddress','order_id','order_id');    }    /**     * 关联订单配送表     */    public function delivery()    {        return $this->hasOne('app\\common\\model\\food\\OrderDelivery','order_id','order_id');    }    /**     * 关联评论表     */    public function comment()    {        return $this->hasOne('app\\common\\model\\food\\Comment','order_id','order_id');    }    /**     * 关联餐桌/包间表     */    public function table()    {        return $this->belongsTo('app\\common\\model\\food\\Table','table_id');    }    /**     * 关联门店表     */    public function shop()    {        return $this->belongsTo('app\\common\\model\\food\\Shop','shop_id');    }    /**     * 格式化到店时间     */    public function getArriveTimeAttr($value)    {        return ['text' => date("m-d H:i",$value), 'value' => $value];    }    /**     * 用户表     */    public function getUserAttr($value,$data)    {        if($data['user_id'] == 0){            return [                'user_id' => '--',                'nickname' => '--'            ];        }        return User::get($data['user_id']);    }    /**     * 订单来源     */    public function getSourceAttr($value)    {        $status = [10 => '自助点单', 20 => '代客点单'];        return ['text' => $status[$value], 'value' => $value];    }	    /**     * 订单类型     */    public function getOrderModeAttr($value)    {        $status = [10 => '堂食', 20 => '外卖', 30 => '自取'];        return ['text' => $status[$value], 'value' => $value];    }	    /**     * 付款方式     */    public function getPayModeAttr($value)    {        $status = ['微信','余额','线下'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 付款状态     */    public function getPayStatusAttr($value)    {        $status = [10 => '待付款', 20 => '已付款', 30 => '后付款'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 商家状态     */    public function getShopStatusAttr($value)    {        $status = [10 => '待接单', 20 => '已接单', 30 => '已接单'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 配送状态     */    public function getDeliveryStatusAttr($value,$data)    {        if($data['order_mode'] == 10){            $status = [10 => '备餐中', 20 => '启菜中', 30 => '上餐完毕'];        }        if($data['order_mode'] == 20){            $status = [10 => '备餐中', 20 => '配送中', 30 => '已配送'];        }        if($data['order_mode'] == 30 or $data['order_mode'] == 40){            $status = [10 => '备餐中', 20 => '待取餐', 30 => '已取餐'];        }        return ['text' => $status[$value], 'value' => $value];    }        /**     * 收货状态     */     public function getReceiptStatusAttr($value,$data)    {        if($data['order_mode'] == 20){            $status = [10 => '待收货', 20 => '已收货'];        }else{            $status = [10 => '待完成', 20 => '已完成'];        }        return ['text' => $status[$value], 'value' => $value];    }    /**     * 退款状态     */     public function getRefundStatusAttr($value)    {        $status = [10 => '待退款', 20 => '已退款'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 订单状态     */    public function getOrderStatusAttr($value)    {        $status = [10 => '进行中', 20 => '被取消', 30 => '已完成', 40 => '退款'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 是否评价     */    public function getIsCmtAttr($value)    {        $status = ['待评价', '已评价'];        return ['text' => $status[$value], 'value' => $value];    }    /**     * 按照分类获取单列表     * $type 类别 all=所有 payment=待付款 comment=待评价 refund=退款/售后     */    public function getList(string $dataType='all', $shop_id = 0, $user_id = 0, string $search = '')    {        // 筛选条件        $filter = [];        $shop_id > 0 && $filter['shop_id'] = $shop_id;         $user_id > 0 && $filter['user_id'] = $user_id;         $model = $this->with(['goods.image','shop','table','comment','delivery'])->order(['order_id' => 'desc']);        switch ((string)$dataType) {            case 'all'; //全部                break;            case 'payment'; //待付款                $filter['pay_status'] = 10;                $filter['order_status'] = 10;                break;            case 'collection'; //待收款                $filter['pay_status'] = 30;                $filter['order_status'] = 10;                break;            case 'shop';//待接单                $model->where('pay_status','>',10);                $filter['shop_status'] = 10;                $filter['order_status'] = 10;                break;            case 'delivery';//待配送                $model->where('shop_status','>',10);                $filter['delivery_status'] = 10;                $filter['order_status'] = 10;                break;            case 'receipt';//待收货                $filter['pay_status'] = 20;                $filter['order_status'] = 10;                $filter['delivery_status'] = 30;                $filter['receipt_status'] = 10;                break;            case 'cancel';//被取消                $filter['order_status'] = 20;                break;            case 'complete';//已完成                $filter['order_status'] = 30;                break;            case 'comment';//待评价                $filter['is_cmt'] = 0;                $filter['order_status'] = 30;                break;            case 'refund';//全部退款                $filter['order_status'] = 40;                break;            case 'refund10';//待退款                $filter['refund_status'] = 10;                $filter['order_status'] = 40;                break;            case 'refund20';//已退款                $filter['refund_status'] = 20;                $filter['order_status'] = 40;                break;        }        return $model->where($filter)->paginate(['list_rows'=>15,'query' => request()->param()]);     }    /**     * 订单详情     */    public static function detail($id)    {        return self::with(['goods' => ['image', 'spec', 'goods'], 'address', 'shop', 'table','delivery'])            ->where(['order_id' => $id])            ->find();    }        /**     * 取消订单     */    public function cancel()    {        //如果已经付款 - 订单取消需要完成退款操作        if ($this->pay_status['value'] == 20){            //余额支付            if($this->pay_mode['value'] == 1){                //退回用户余额                $user = User::get($this->user_id);		        $user->money = ['inc', $this->pay_price];//增加余额		        $user->pay = ['dec', $this->pay_price];//减少消费金额		        $record = new Record;		        $arr = [];		        $arr[0] = [    			    'order_no' => $this->order_no,                    'money' => $this->pay_price,                    'user_id' => $this->user_id,                    'shop_id' => $this->shop_id,                    'applet_id' => $this->applet_id,                    'mode' => 30,//退款                    'type' => 10,//余额                    'remark' => '取消订单'                ];                //会员对积分进行操作		        if($user['v']['value'] > 0){		            $user->score = ['dec', $this->pay_price];//减少积分		            $arr[1] = $arr[0];                    $arr[1]['mode'] = 50;//扣减		            $arr[1]['type'] = 90;//积分		        }		        $user->save();        		$record->saveAll($arr);        		//发送退款申请状态提醒订阅消息                $this->postTpl('refund',$this->order_id);            }            //微信支付            if($this->pay_mode['value'] == 0 and !empty($this->transaction_id)){                //退回用户微信钱包                $values = SettingModel::getItem('wxpay',$this->applet_id);                $WxPay = new WxPay($values);                if(!$result = $WxPay->refunds($this->transaction_id,$this->order_no,$this->pay_price,$this->pay_price,'api/food.notify/orderRefund/appletid/'.$this->applet_id,'取消订单')){                    $this->error = $WxPay->getError();                    return false;                }            }        }        //堂食扫码释放餐桌        if($this->table_id > 0){            Table::where(['table_id' => $this->table_id])->update(['status' => 10]);        }        return $this->save([            'order_status' => 20,            'pay_status' => 10        ]);    }    /**     * 商家接单     */    public function setShopStatus()    {        //发送商家接单订阅消息        $this->postTpl('receive',$this->order_id);        return $this->save([            'shop_status' => 20,            'shop_time' => time()        ]);    }        /**     * 确认发货     */    public function setDelivery($company='', $shop_clerk_id='')    {        // 开启事务        Db::startTrans();        try {            //外卖配送            if($this->order_mode['value'] == 20){                if($this->delivery_status['value']==10){                    $data = [                        'shop_status' => 30,//已推送外卖订单                        'shop_time' => time(),                        'delivery_status' => 20                    ];                    if($company == 'self'){                        if(empty($shop_clerk_id)){                            $clerk = ShopClerk::where(['shop_id' => $this->shop_id,'status' => 20])->find(); //获取店员信息                        }else{                            $clerk = ShopClerk::get($shop_clerk_id); //获取店员信息                        }                        $dev = [                            'linkman' => $clerk['real_name'],                            'phone' => $clerk['phone'],                            'delivery_status' => 30,  //已到店                            'order_no' => $this->order_no,                        ];                        //骑手接单提醒                        $this->postTpl('horseman',$this->order_id);                    }                    if($company == 'sf'){                        $sf = new Delivery('sf');                        $user_location = explode(',',$this['address']['location']);//拆分收货人定位经纬度		                $shop_location = explode(',',$this['shop']['coordinate']);//拆分门店定位经纬度		                $time = time();                		$post_data = [                			'shop_id' => $this['shop']['sf_shop_id'],//$this->shop_id,//店铺ID                			'shop_type' => 1,//店铺ID类型 1：顺丰店铺ID ；2：接入方店铺ID                			'shop_order_id' => $this['order_no'],//商家订单号	不允许重复                			'order_source' => $this['shop']['shop_name'],//订单接入来源                			'order_sequence' => '外卖'.$this['row_no'].'号',//取货序号                			'lbs_type' => 2,//坐标类型	1：百度坐标，2：高德坐标                			'pay_type' => 1,//用户支付方式	1：已付款 0：货到付款                			'receive_user_money' => 0,//代收金额,单位：分                			'order_time' => $this['pay_time'],//用户下单时间	秒级时间戳                			'is_appoint' => 0,//是否是预约单,0：非预约单；1：预约单                			'expect_time' => $time + 1800,//用户期望送达时间	预约单需必传,秒级时间戳                			'is_insured' => 0,//是否保价，0：非保价；1：保价                			'declared_value' => 0,//保价金额,单位：分                			'is_person_direct' => 0,//是否是专人直送订单，0：否；1：是                			'declared_value' => 0,//保价金额	单位：分                			'gratuity_fee' => 0,//订单小费，不传或者传0为不加小费	单位分，加小费最低不能少于100分                			'remark' => $this['message'],//订单备注                			'rider_pick_method' => 1,//物流流向	1：从门店取件送至用户,2：从用户取件送至门店                			'return_flag' => 511,	//返回字段控制标志位（二进制）	1:商品总价格，2:配送距离，4:物品重量，8:起送时间，16:期望送达时间，32:支付费用，64:实际支持金额，128:优惠卷总金额，256:结算方式,例如全部返回为填入511                			'push_time' => $time,                			'version' => 17,                			//发货店铺信息；Obj,平台级开发者需要传入                			'shop' => [                				'shop_name' => $this['shop']['shop_name'],//店铺名称                				'shop_phone' => $this['shop']['phone'],//店铺电话                				'shop_address' => $this['shop']['address'],//店铺地址                				'shop_lng' => $shop_location[1],//店铺经度                				'shop_lat' => $shop_location[0]//店铺纬度		                			],                			'receive' => [                				'user_name' => $this['address']['name'],//用户姓名                				'user_phone' => $this['address']['phone'],//用户电话                				'user_lng' => $user_location[1],//用户地址经度                				'user_lat' => $user_location[0],//用户地址纬度                				'user_address' => $this['address']['detail'], //用户地址                				'city_name' => $this['address']['city'] //发单城市,用来校验是否跨城；请填写城市的中文名称，如北京市                			],                			'order_detail' => [                				'total_price' => $this['pay_price']*100,//用户订单总金额（单位：分）                				'product_type' => 1, //物品类型,测试店铺请填写1，否则会造成【没有匹配的计价规则或计价规则已失效】                				'user_money' => $this['pay_price']*100, //实收用户金额（单位：分）                				'shop_money' => $this['pay_price']*100,//实付商户金额（单位：分）                				'weight_gram' => 1,//物品重量（单位：克）                				'volume_litre' => 5,//物品体积（单位：升）                				'delivery_money' => 1,//商户收取的配送费（单位：分）                				'product_num' => sizeof($this['goods']),//物品个数                				'product_type_num' => sizeof($this['goods'])//物品种类个数                			]                		];                		$product_detail = [];//商品列表详情                		foreach ($this['goods'] as $item){                			$product_detail[] = [                				'product_name' => $item['goods_name'],//物品名称                				'product_id' => $item['goods_id'],//物品ID                				'product_num' => $item['total_num'],//物品数量                				'product_price' => $item['goods_price'],//物品价格                				'product_unit' => '个',//物品单位                				'product_remark' => '',//备注                				'item_detail'=> ''//详情                			];                		}                		$post_data['order_detail']['post_data'] = $product_detail;//商品详情                        if($result = $sf->addOrder($post_data)){                            $real_pay_money = (int)$result['result']['real_pay_money'];//配送费                            $real_pay_money = round($real_pay_money / 100,2); //四舍五入保留两位小数                            $dev = [                                'price' => $real_pay_money, //配送费                                'distance' => $result['result']['delivery_distance_meter'] * 100,//配送距离                                'order_no' => $result['result']['sf_order_id'] //顺丰订单号（标准默认为int，可以设置为string）                            ];                        }else{                            $this->error = $sf->getError();                            return false;                         }                    }                    if($company == 'dada'){                        $dada = new Delivery('dada');                        $user_location = explode(',',$this['address']['location']);//拆分收货人定位经纬度		                $shop_location = explode(',',$this['shop']['coordinate']);//拆分门店定位经纬度		                $city_code = $dada->getCiytCode($this['shop']['city']);		                $post_data = [                			'shop_no' => $this['shop']['dada_shop_id'],//是 门店编号                			'origin_id' => $this['order_no'],//是 第三方订单ID                			'city_code' => $city_code,//是 订单所在城市的code                			'cargo_price' => $this['pay_price'],//是 订单金额                			'is_prepay' => 0,//是否需要垫付 1:是 0:否 (垫付订单金额，非运费)                			'receiver_name' => $this['address']['name'],//是 收货人姓名                			'receiver_address' => $this['address']['detail'],//是 收货人地址                			'callback' => base_url() . 'api/food.delivery/dada',//是 回调URL                			'receiver_lat' => $user_location[0], //否 收货人地址纬度                			'receiver_lng' => $user_location[1],//否 收货人地址经度                			'receiver_phone' => $this['address']['phone'],//否 收货人手机号                			//'tips' => 0,//否 小费（单位：元，精确小数点后一位）                			'info' => $this['message'],//否 订单备注                			//'cargo_type' => 1,//否 订单商品类型：食品小吃-1,饮料-2,鲜花-3,文印票务-8,便利店-9,水果生鲜-13,同城电商-19, 医药-20,蛋糕-21,酒品-24,小商品市场-25,服装-26,汽修零配-27,数码-28,小龙虾-29,火锅-51,其他-5                			'cargo_weight' => 0.1,//是	订单重量（单位：Kg）                			//'origin_mark_no' => '河马云店',//否	订单来源编号                			//'is_use_insurance' => 0,//是否使用保价费（0：不使用保价，1：使用保价； 同时，请确保填写了订单金额（cargo_price））	                		];                        if($pre = $dada->preOrder($post_data)){                            $dada_config = get_addons_config('dada');//获取配送设置                            //如果是余额支付配送费                            if($dada_config['pay_mode'] == 0){                                $applet = Applet::detail();                                if($user = UserModel::withoutGlobalScope()->find(applet['user_id'])){                                    //判断商家余额                                    if($user['money'] < $pre['dada']['result']['fee']){                                        //发送余额不足模板消息************************                                        $this->error = '账户余额不足';                                        return false;                                     }                                    //扣取配送费                                    $user->money = ['dec',$pre['dada']['result']['fee']];                                    $user->pay = ['inc', $pre['dada']['result']['fee']];//增加消费金额		                            $user->score = ['inc', $pre['dada']['result']['fee']];//增加积分                                    $user->save();                                    $record = new RecordModel;                                    $record->save([                                        'type' => 10,//余额                                        'mode' => 50,//扣减                                        'order_no' => $this->order_no,                                        'money' => $pre['dada']['result']['fee'],                                        'remark' => '第三方配送费',                                        'user_id' => $applet['user_id']                                     ]);                                }                            }                            if($result = $dada->addOrder(['delivery_no' => $pre['dada']['result']['deliveryNo']])){                                $dev = [                                    'price' => $pre['dada']['result']['fee'], //配送费                                    'distance' => (int)$pre['dada']['result']['distance'],//配送距离                                    'order_no' => $this->order_no //商家单号                                    //'order_no' => $pre['dada']['result']['deliveryNo'] //达达单号                                ];                            }else{                                $this->error = $dada->getError();                                return false;                            }                        }else{                            $this->error = $dada->getError();                            return false;                         }                     }                    if($company == 'uu'){                        $uu = new Delivery('uu');                        $user_location = explode(',',$this['address']['location']);//拆分收货人定位经纬度		                $shop_location = explode(',',$this['shop']['coordinate']);//拆分门店定位经纬度		                $post_data = [                			'origin_id' => $this['order_id'],//第三方对接平台订单id                			'from_address' => $this['shop']['address'],//起始地址                			//'from_usernote' => '',//起始地址具体门牌号(可为空)                			'to_address' => $this['address']['detail'],//目的地址                			//'to_usernote' => '',//目的地址具体门牌号(可为空)                			'city_name' => $this['shop']['city'],//订单所在城市名 称(如郑州市就填”郑州市“，必须带上“市”)                			'county_name' => $this['shop']['district'],//订单所在县级地名称(如金水区就填“金水区”)(可为空)                			'subscribe_type' => '0',//预约类型 0实时订单 1预约取件时间(可为空)                			//'subscribe_time' => '',//预约时间（如：2015-06-18 12:00:00）没有可以传空字符串(可为空)                			'send_type' => '0',//订单小类 0帮我送(默认) 1帮我买                			'to_lat' => $user_location[0],//目的地坐标纬度，如果无，传0(坐标系为百度地图坐标系)                			'to_lng' => $user_location[1],//目的地坐标经度，如果无，传0(坐标系为百度地图坐标系)                			'from_lat' => $shop_location[0],//起始地坐标纬度，如果无，传0(坐标系为百度地图坐标系)                			'from_lng' => $shop_location[1] //起始地坐标经度，如果无，传0(坐标系为百度地图坐标系)	                		];                        if($pre = $uu->preOrder($post_data)){                            $uu_config = get_addons_config('uu');//获取配送设置                            //如果是余额支付配送费                            if($uu_config['pay_mode'] == 0){                                $applet = Applet::detail();                                if($user = UserModel::withoutGlobalScope()->find($applet['user_id'])){                                    //判断商家余额                                    if($user['money'] < $pre['uu']['need_paymoney']){                                        //发送余额不足模板消息************************                                        $this->error = '账户余额不足';                                        return false;                                     }                                    //扣取配送费                                    $user->money = ['dec',$pre['uu']['need_paymoney']];                                    $user->pay = ['inc', $pre['uu']['need_paymoney']];//增加消费金额		                            $user->score = ['inc', $pre['uu']['need_paymoney']];//增加积分                                    $user->save();                                    $record = new RecordModel;                                    $record->save([                                        'type' => 10,//余额                                        'mode' => 50,//扣减                                        'order_no' => $this->order_no,                                        'money' => $pre['uu']['need_paymoney'],                                        'remark' => '第三方配送费',                                        'user_id' => $applet['user_id']                                     ]);                                }                            }                            $post_data = [                    			'price_token' => $pre['uu']['price_token'],//金额令牌，计算订单价格接口返回的price_token                    			'order_price' => $pre['uu']['total_money'],//订单金额，计算订单价格接口返回的total_money                    			'balance_paymoney' => $pre['uu']['need_paymoney'],//实际余额支付金额计算订单价格接口返回的need_paymoney                    			'receiver' => $this['address']['name'],//收件人                    			'receiver_phone' => $this['address']['phone'],//收件人电话 手机号码；虚拟号码格式（手机号_分机号码）例如：13700000000_1111                    			'callback_url' => base_url() . 'api/food.delivery/uu',//订单提交成功后及状态变化的回调地址                    			'push_type' => '0',//推送方式（0 开放订单，2测试订单）默认传0即可                    			'special_type' => '0',//是否需要保温箱 1需要 0不需要                    			'callme_withtake' => '0',//取件是否给我打电话 1需要 0不需要                    			'pubusermobile' => $this['shop']['phone'],//发件人电话，（如果为空则是用户注册的手机号）                    			'pay_type' => '1' //支付方式：1=企业支付 0账户余额支付（企业余额不足自动转账户余额支付）	                    		];                    		!empty($this['message']) && $post_data['note'] = $this['message'];//订单备注 最长140个汉字                            if($result = $uu->addOrder($post_data)){                                $dev = [                                    'price' => $pre['uu']['need_paymoney'], //配送费                                    'distance' => $pre['uu']['distance'],  //配送距离                                    'order_no' => $result['ordercode']                                ];                            }else{                                $this->error = $uu->getError();                                return false;                            }                        }else{                            $this->error = $uu->getError();                            return false;                        }                     }                    if($company == 'make'){                        $make = new Delivery('make');                        $post_data = [                			'fromcoord' => $this['shop']['coordinate'],//起点地址坐标                            'tocoord' => $this['address']['location'],//终点地址坐标                            'shop_id' => $this['shop']['make_shop_id'] //店铺ID	                		];                        if($pre = $make->preOrder($post_data)){                            $make_config = get_addons_config('make');//获取配送设置                            //如果是余额支付配送费                            if($make_config['pay_mode'] == 0){                                $applet = Applet::detail();                                if($user = UserModel::withoutGlobalScope()->find($applet['user_id'])){                                    //判断商家余额                                    if($user['money'] < $pre['make']['data']['total_price']){                                        //发送余额不足模板消息************************                                        $this->error = '账户余额不足';                                        return false;                                     }                                    //扣取配送费                                    $user->money = ['dec',$pre['make']['data']['total_price']];                                    $user->pay = ['inc', $pre['make']['data']['total_price']];//增加消费金额    		                        $user->score = ['inc', $pre['make']['data']['total_price']];//增加积分                                    $user->save();                                    $record = new RecordModel;                                    $record->save([                                        'type' => 10,//余额                                        'mode' => 50,//扣减                                        'order_no' => $this->order_no,                                        'money' => $pre['make']['data']['total_price'],                                        'remark' => '第三方配送费',                                        'user_id' => $applet['user_id']                                     ]);                                }                            }                            		                    //附加数据json格式，回调返回该参数                    		$attach = [                    			'name' => $this['shop']['shop_name']                    		];                    		$post_data = [                    			'shop_id' => $this['shop']['make_shop_id'],//$this->shop_id,//店铺ID                    			'goods_name' => $this['shop']['shop_name'],//商品名称                    			'order_no' => $this['order_no'],//商家订单号	不允许重复                    			'notify_url' => base_url() . 'api/food.delivery/make',//回调地址                    			'pay_price' => $pre['make']['data']['total_price'],//跑腿支付金额                    			'total_price' => $pre['make']['data']['total_price'],//跑腿总金额                    			'pick_time' => date("Y-m-d H:i",time()),//取件时间 格式2020-09-30 00:00                    			'remark' => $this['message'],//订单备注                    			'attach' => json_encode($attach,JSON_UNESCAPED_UNICODE),                    		];                    		$user_location = explode(',',$this['address']['location']);//拆分收货人定位经纬度		                    $shop_location = explode(',',$this['shop']['coordinate']);//拆分门店定位经纬度                    		//地址信息                    		$address = [                    			'begin_detail' => $this['shop']['address'],                    			'begin_address' => $this['shop']['province'] . $this['shop']['city'] . $this['shop']['district'] . $this['shop']['address'],                    			'begin_lat' => $shop_location[0],                    			'begin_lng' => $shop_location[1],                    			'begin_username' => $this['shop']['linkman'],                    			'begin_phone' => $this['shop']['phone'],                    			'end_detail' => $this['address']['detail'],                    			'end_address' => $this['address']['province'] . $this['address']['city'] . $this['address']['district'] . $this['address']['detail'],                    			'end_lat' => $user_location[0],                    			'end_lng' => $user_location[1],                    			'end_username' => $this['address']['name'],                    			'end_phone' => $this['address']['phone']                    		];                    		$post_data['address'] = json_encode($address,JSON_UNESCAPED_UNICODE);                    		//商品详情                    		$goods = [];                    		foreach ($this['goods'] as $vo) {                    			$goods[] = [                    				'name' => $vo['goods_name'],//物品名称                    				'price' => $vo['goods_price'],//物品价格                    				'num' => $vo['total_num'],//物品数量                    			];                    		}                    		$post_data['goods'] = json_encode($goods,JSON_UNESCAPED_UNICODE);                            if($result = $make->addOrder($post_data)){                                $dev = [                                    'price' => $pre['make']['data']['total_price'], //配送费                                    'distance' => $pre['make']['data']['distance'] * 1000,//配送距离                                    'order_no' => $result['data']['order_number']                                ];                            }else{                                $this->error = $make->getError();                                return false;                            }                        }else{                            $this->error = $make->getError();                            return false;                         }                     }                    if($company == 'shansong'){                        $shansong = new Delivery('shansong');                    	$user_location = explode(',',$this['address']['location']);//拆分收货人定位经纬度	                    $shop_location = explode(',',$this['shop']['coordinate']);//拆分门店定位经纬度                        $post_data = [                			'cityName' => $this['shop']['city'],//城市名称                            'appointType' => 0,//预约类型Integer	0立即单，1预约单                            'sender' => [//寄件人信息                                'fromAddress' => $this['shop']['district'],//寄件地址                                'fromAddressDetail' =>  $this['shop']['address'],//寄件详细地址	                                'fromSenderName' =>	$this['shop']['shop_name'],       //寄件人姓名	                                'fromMobile' =>	$this['shop']['phone'],//寄件人电话，支持11位手机号;支持座机号(格式：010-12345678)                                'fromLatitude' => $shop_location[0],//寄件纬度,只支持百度坐标系                                'fromLongitude' => $shop_location[1]//寄件经度,只支持百度坐标系                            ],                            'receiverList' => [//收件人信息                                'orderNo' => $this['order_no'],	//第三方平台流水号	                                'toAddress' => $this['address']['district'],//收件地址	                                'toAddressDetail' => $this['address']['detail'],//收件详细地址	                                'toLatitude' => $user_location[0],//收件纬度,只支持百度坐标系                                'toLongitude' => $user_location[1],//收件经度,只支持百度坐标系                                'toReceiverName' => $this['address']['name'],//收件人姓名	                                'toMobile' => $this['address']['phone'],//收件联系人,支持11位手机号；支持座机号格式：010-12345678                                'goodType' => 6,//	物品类型,6=餐饮                                'weight' =>1,//物品重量，单位为kg                                'remarks' => empty($this['message'])?'无':$this['message'],//备注	                            ]                		];                        if($pre = $shansong->preOrder($post_data)){                            $total_price = $pre['shansong']['totalFeeAfterSave']*100;//配送费用                            $config = get_addons_config('shansong');//获取配送设置                            //如果是余额支付配送费                            if($make_config['pay_mode'] == 0){                                $applet = Applet::detail();                                if($user = UserModel::withoutGlobalScope()->find($applet['user_id'])){                                    //判断商家余额                                    if($user['money'] < $total_price){                                        //发送余额不足模板消息************************                                        $this->error = '账户余额不足';                                        return false;                                     }                                    //扣取配送费                                    $user->money = ['dec',$total_price];                                    $user->pay = ['inc', $total_price];//增加消费金额    		                        $user->score = ['inc', $total_price];//增加积分    		                        $user->save();                                    $record = new RecordModel;                                    $record->save([                                        'type' => 10,//余额                                        'mode' => 50,//扣减                                        'order_no' => $this->order_no,                                        'money' => $total_price,                                        'remark' => '第三方配送费',                                        'user_id' => $applet['user_id']                                     ]);                                }                            }                    		$post_data = [                    		    'issOrderNo' => $pre['shansong']['orderNumber']                    		];                            if($result = $shansong->addOrder($post_data)){                                $dev = [                                    'price' => $total_price, //配送费                                    'distance' => $pre['shansong']['totalDistance'],//配送距离                                    'order_no' => $result['orderNumber']                                ];                            }else{                                $this->error = $shansong->getError();                                return false;                            }                        }else{                            $this->error = $shansong->getError();                            return false;                         }                     }                    $dev['company'] = $company;                    $dev['delivery_time'] = time();                    $dev['shop_id'] = $this->shop_id;                    $dev['applet_id'] = $this->applet_id;                    $this->delivery()->save($dev);                }else{                    //外卖配送完毕                    $this->delivery->save([                        'delivery_status' => 50,                        'delivery_time' => time(),                        'status' => 30                    ]);                    $data = [                        'delivery_status' => 30                    ];                }            }else{                //不是扫码点餐                if($this->table_id == 0){                    Device::push($this->shop_id,'rows',$this->row_no);//叫号                    //发送模板消息，取餐提醒通知                    $this->postTpl('take',$this->order_id);                }else{                    //发送模板消息，订单完成通知                    $this->postTpl('finish',$this->order_id);                }                //非外卖配送                $data = [                    'delivery_status' => 30                ];              }            $data['delivery_time'] = time();            $this->save($data);            Db::commit();            return true;        } catch (\Exception $e) {            Db::rollback();        }        return false;    }        /**     * 取消已经推送的外卖订单     */    public function cancelDelivery()    {        $data = [            'shop_status' => 20,            'shop_time' => time(),            'delivery_status' => 10,            'delivery_time' => 10        ];        if($this->delivery['company']['value'] != 'self'){            $dv = new Delivery($this->delivery['company']['value']);            if(!$result = $dv->cancelOrder($this->delivery['order_no'])){                $this->error = $dv->getError();                return false;            }        }         // 开启事务        Db::startTrans();        try {            //退款 --- 待补充            OrderDelivery::where('order_delivery_id',$this->delivery['order_delivery_id'])->delete();            $this->save($data);            Db::commit();            return true;        } catch (\Exception $e) {            Db::rollback();        }        return false;    }    /**     * 设置配送状态     */    public function setDeliveryStatus(array $data = [])    {        $delivery = [            'delivery_status' => $data['delivery_status'],            'delivery_time' => time()        ];        if($data['delivery_status'] == 40){            $this->postTpl('delivery',$this->order_id);//骑手配送订阅消息        }        if($data['delivery_status'] == 50){            $delivery['status'] = 30;            $this->save([                'delivery_status' => 30,                'delivery_time' => time()            ]);        }        return $this->delivery->save($delivery);    }    /**     * 确认收到用户付款（后付费用户）     */    public function collection()    {        // 开启事务        Db::startTrans();        try {            //如果该用户存在则执行下列操作，代客非会员下单不会执行            if($this->user_id > 0){                $user = User::get($this->user_id);                $user->pay = ['inc', $this->pay_price];//增加消费金额                                                //添加交易记录                $record = new Record;                $arr = [];                $arr[0] = [                    'order_no' => $this->order_no,                    'money' => $this->pay_price,                    'user_id' => $this->user_id,                    'shop_id' => $this->shop_id,                    'applet_id' => $this->applet_id,                    'mode' => 20,//消费                    'type' => 20,//现金                    'remark' => '当面付款'                ];                                //会员对积分进行操作                if($user['v']['value'] > 0){                    $user->score = ['inc', $this->pay_price];//增加消费积分                    $arr[1] = $arr[0];                    $arr[1]['type'] = 90;//积分                }                $user->save();                $record->saveAll($arr);            }            $this->save([                'pay_mode' => 2,                'pay_status' => 20,                'pay_time' => time()            ]);            Db::commit();            return true;        } catch (\Exception $e) {            Db::rollback();        }        return false;    }    /**     * 确认收货 - 清台     */    public function receipt()    {        $this->postTpl('finish',$this->order_id);        //堂食扫码释放餐桌        if($this->table_id > 0){            Table::where(['table_id' => $this->table_id])->update(['status' => 10]);        }        //判断是否是进入分账        if(!empty($this->transaction_id)){            //判断外卖订单是否分账配送费            $delivery_fee = 0;//配送费            if($this->order_mode['value'] == 20){                if($dv_company = get_addons_info($this->delivery['company']['value'])){                    if($dv_company['status'] == 1){                        if($dv_config = get_addons_config($dv_company['name'])){                            if($dv_config['pay_mode'] == 1){                                $delivery_fee = $this->delivery['price'];//配送费                            }                        }                    }                }            }            //账单分账            $wxpay = new WxPay(SettingModel::getItem('wxpay',$this->applet_id));            $wxpay->divide([                'out_order_no' => $this->order_no,                'transaction_id' => $this->transaction_id,                'total' => $this->pay_price,            ],$this->applet_id,$delivery_fee);//进行分账              }        return $this->save([            'receipt_status' => 20,            'receipt_time' => time(),            'order_status' => 30        ]);    }    /**     * 退款处理     */    public function refund($is_refund = 0)    {        if($this->refund_price > $this->pay_price){            $this->error = '退款金额不可大于实付金额';            return false;        }        //同意退款        if($is_refund==1){            // 开启事务            Db::startTrans();            try {                //余额退款                if($this->pay_mode['value'] == 1){                    //余额变动                    $user = User::get($this->user_id);                    $user->money = ['inc',$this->refund_price];//返回余额                    $user->pay = ['dec', $this->refund_price];//扣减消费金额                                        $record = new Record;                    $arr = [];                    $arr[0] = [                        'order_no' => $this->order_no,                        'money' => $this->refund_price,                        'user_id' => $this->user_id,                        'shop_id' => $this->shop_id,                        'applet_id' => $this->applet_id,                        'remark' => '订单退款',                        'mode' => 30,                        'type' => 10,                    ];                                        //会员对积分进行操作                    if($user['v']['value'] > 0){                        $user->score = ['dec', $this->refund_price];//扣减积分                        $arr[1] = $arr[0];                        $arr[1]['mode'] = 50;                        $arr[1]['type'] = 90;                    }                    $user->save();            		$record->saveAll($arr);                    $this->save([                        'refund_status' => 20,                        'refund_time' => time()                    ]);                    //发送退款申请状态提醒订阅消息                    $this->postTpl('refund',$this->order_id);                }                //微信退款处理                if($this->pay_mode['value'] == 0){                    $values = SettingModel::getItem('wxpay',$this->applet_id);                    $WxPay = new WxPay($values);                    if(!$result = $WxPay->refunds($this->transaction_id,$this->order_no,$this->refund_price,$this->pay_price,'api/food.notify/orderRefund/appletid/'.$this->applet_id,$this->refund_desc)){                        $this->error = $WxPay->getError();                        return false;                    }                }                Db::commit();                return true;            } catch (\Exception $e) {                Db::rollback();            }            return false;        }        //拒绝退款        // 开启事务        Db::startTrans();        try {            OrderGoods::where('order_id',$this->order_id)->update([                'refund_num' => 0,                'refund_price' => 0            ]);            $this->save([                'order_status' => 10,                'refund_status' => 10,                'refund_price' => 0            ]);            //发送退款申请状态提醒订阅消息            $this->postTpl('refund',$this->order_id);            Db::commit();            return true;        } catch (\Exception $e) {            Db::rollback();        }        return false;    }    /**     * 发送订阅消息 - 点餐     * @param  string $mode receive=商家接单通知 horseman=骑手取货通知 delivery=订单配送通知 take=取餐提醒 finish=订单完成通知 refund=退款状态通知     * @param  [type] $order 订单     */    public function postTpl($mode,$order_id)    {        //获取订阅消息配置        $order = Order::detail($order_id);        //判断用户是否存在（代客下单不回发送订阅消息）        if(!isset($order['user']['open_id']) or empty($order['user']['open_id'])){            return true;        }        //获取订阅消息配置        $values = Setting::getItem('wxapptpl',$order['applet_id']);        $data = [];        $template_id = '';        //商家接单通知        if($mode=='receive' AND !empty($values['receive'])){            $template_id = trim($values['receive']);            $data = [                'thing2' => [                    'value' => $order['shop']['shop_name']//商家名称{{thing2.DATA}}                ],                'character_string6' => [                    'value' => $order['order_no']//订单编号{{character_string6.DATA}}                ],                'phrase7' => [                    'value' => '已接单' //订单状态{{phrase7.DATA}}                ],                'phone_number10' => [                    'value' => date('Y-m-d h:i',time())//接单时间{{phone_number10.DATA}}                ],                'thing5' => [                    'value' => '商家备餐中，点击查看详情>>' //温馨提示{{thing5.DATA}}                ]            ];        }        //骑手取货通知        if($mode=='horseman' AND !empty($values['horseman'])){            $template_id = trim($values['horseman']);            $data = [                'thing1' => [                    'value' => $order['shop']['shop_name']//商家{{thing1.DATA}}                ],                'phrase2' => [                    'value' => '骑手已接单' //状态{{phrase2.DATA}}                ],                'thing4' => [                    'value' => '待骑手配送，点击查看详情>>' //备注{{thing4.DATA}}                ]            ];        }        //取餐提醒        if($mode=='take' AND !empty($values['take'])){            $template_id = trim($values['take']);            $order['order_mode']['value'] == 10 && $status = '堂食';            $order['order_mode']['value'] == 20 && $status = '外卖';            $order['order_mode']['value'] == 30 && $status = '外带';            $order['order_mode']['value'] == 40 && $status = '外带';            $data = [                'thing23' => [                    'value' => $order['shop']['shop_name']//门店名称{{thing23.DATA}}                ],                'character_string12' => [                    'value' => $order['row_no']//取餐编号{{character_string12.DATA}}                ],                'phrase30' => [                    'value' => $status //订单类型{{phrase30.DATA}}                ],                'phrase16' => [                    'value' => '待领取' //订单状态{{phrase16.DATA}}                ],                'thing7' => [                    'value' => '请前往领餐处，点击查看详情>>' //温馨提醒{{thing7.DATA}}                ]            ];        }        //订单配送通知        if($mode=='delivery' AND !empty($values['delivery'])){            $template_id = trim($values['delivery']);            $data = [                'thing1' => [                    'value' => $order['shop']['shop_name']//出餐门店{{thing1.DATA}}                ],                'character_string2' => [                    'value' => $order['order_no']//订单号{{character_string2.DATA}}                ],                'phrase15' => [                    'value' => '配送中' //订单状态{{phrase15.DATA}}                ],                'time4' => [                    'value' => date('Y-m-d h:i',time())//送出时间{{time4.DATA}}                ],                'thing5' => [                    'value' => '30分钟内送达，点击查看详情>>' //备注{{thing5.DATA}}                ]            ];        }        //订单完成通知        if($mode=='finish' AND !empty($values['finish'])){            $template_id = trim($values['finish']);            $order['order_mode']['value'] == 10 && $status = '堂食';            $order['order_mode']['value'] == 20 && $status = '外卖';            $order['order_mode']['value'] == 30 && $status = '外带';            $order['order_mode']['value'] == 40 && $status = '外带';            $data = [                'thing13' => [                    'value' => $order['shop']['shop_name']//门店名称{{thing13.DATA}}                ],                'phrase11' => [                    'value' => '已完成'//订单状态{{phrase11.DATA}}                ],                'thing14' => [                    'value' => $status //订单类型{{thing14.DATA}}                ],                'time12' => [                    'value' => date('Y-m-d h:i',time())//完成时间{{time12.DATA}}                ],                'thing5' => [                    'value' => '订单餐食已送完，点击查看详情>>' //备注{{thing5.DATA}}                ]            ];        }        //退款状态通知        if($mode=='refund' AND !empty($values['refund'])){            $template_id = trim($values['refund']);            if($order['refund_status']['value']==20){                $status = '退款成功';                $msg = '退款已原路返回，点击查看详情>>';            }else{                $status = '退款失败';                $msg = '不符合退款要求，点击查看详情>>';            }            $data = [                'phrase1' => [                    'value' => $status//退款状态 {{phrase1.DATA}}                ],                'amount2' => [                    'value' => '￥'.$order['refund_price'].'元'//退款金额 {{amount2.DATA}}                ],                'time4' => [                    'value' => date('Y-m-d h:i',time()) //处理时间 {{time4.DATA}}                ],                'thing5' => [                    'value' => $msg //温馨提示 {{thing5.DATA}}                ]            ];        }        //发送订阅消息        if(sizeof($data) > 0 AND $template_id != ''){            $wx = new Wechat;            $queryarr = [                'touser' => $order['user']['open_id'],                'template_id' => $template_id,                'page' => 'pages/order/detail?id='.$order_id,                'data' => $data            ];            $wx->sedSubscribeMsg($order['applet_id'],$queryarr);        }        return true;    }    /**     * 清除订单记录     */    public function remove($order_id)    {        $filter['order_id'] = $order_id;        // 开启事务        Db::startTrans();        try {            $this->where($filter)->delete();            OrderAddress::where($filter)->delete();            OrderDelivery::where($filter)->delete();            OrderGoods::where($filter)->delete();            Db::commit();            return true;        } catch (\Exception $e) {            Db::rollback();        }        return false;    }    /**     * 获取订单分类统计     */    public function getOrderClassCount($dataType='all',$shop_id=0,$user_id=0)    {        // 筛选条件        $filter = [];        $shop_id > 0 && $filter['shop_id'] = $shop_id;        $user_id > 0 && $filter['user_id'] = $user_id;        $model = $this->order(['order_id' => 'desc']);        // 订单数据类型        switch ((string)$dataType) {            case 'all'; //全部                break;            case 'payment'; //待付款                $filter['pay_status'] = 10;                $filter['order_status'] = 10;                break;            case 'collection'; //待收款                $filter['pay_status'] = 30;                $filter['order_status'] = 10;                break;            case 'shop';//待接单                $model->where('pay_status','>',10);                $filter['order_status'] = 10;                $filter['shop_status'] = 10;                break;            case 'delivery';//待配送                $model->where('shop_status','>',10);                $filter['order_status'] = 10;                $filter['delivery_status'] = 10;                break;            case 'receipt';//待收货                $filter['order_status'] = 10;                $filter['delivery_status'] = 30;                $filter['receipt_status'] = 10;                break;            case 'cancel';//被取消                $filter['order_status'] = 20;                break;            case 'complete';//已完成                $filter['order_status'] = 30;                break;            case 'comment';//待评价                $filter['is_cmt'] = 0;                $filter['order_status'] = 30;                break;            case 'refund';//全部退款                $filter['order_status'] = 40;                break;            case 'refund10';//待退款                $filter['refund_status'] = 10;                $filter['order_status'] = 40;                break;            case 'refund20';//已退款                $filter['refund_status'] = 20;                $filter['order_status'] = 40;                break;        }        return $model->where($filter)->count();    }    /**     * 生成排队号     */    public static function rowNo($shop_id)    {        $rowno = Cache::get('food_rowno_' . self::$applet_id,[]);        if(isset($rowno[$shop_id])){            $row_no = (int)$rowno[$shop_id];            $row_no++;          }else{            $row_no = 1;        }        //有效期时间,截至到当天23:59:59        $time = strtotime(date('Y-m-d').'23:59:59')-time();        $rowno[$shop_id] = $row_no;        Cache::set('food_rowno_' . self::$applet_id, $rowno,$time);        $str_row_no = (string)$row_no;        $lan = strlen($str_row_no);        for($n=$lan;$n<4;$n++){            $str_row_no = '0'.$str_row_no;        }        return $str_row_no;    }    /**     * 根据时间段统计数量     */    public static function getDateCount($data)    {        // 筛选条件        $filter = [];        $data['shop_id'] > 0 && $filter['shop_id'] = $data['shop_id'];        $model = self::where('create_time','>',$data['star'])->where('create_time','<',$data['end'])->where($filter);        $count = [            'all' => $model->count(),            'tang' => $model->where(['order_mode'=> 10])->count(),            'wai' => $model->where(['order_mode'=> 20])->count(),            'qu' => $model->where(['order_mode'=> 30])->count(),            'refund' => $model->where(['order_status' => 40])->count(),        ];        return $count;    }    /**     * 根据条件统计数量     */    public static function getCount($shop_id = 0)    {        // 筛选条件        $filter = [];        $shop_id > 0 && $filter['shop_id'] = $shop_id;                $count = array();        $count['all'] = [            'all' => self::where($filter)->count(),//全部            'refund' => self::where($filter)->where(['order_status' => 40,'refund_status'=>10])->count(),//待退款        ];        //今天        $star = strtotime(date('Y-m-d 00:00:00',time()));        $count['today'] = [            'all' => self::where($filter)->where('create_time','>',$star)->count(),            'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->count(),        ];        //昨天        $star = strtotime("-1 day");        $end = strtotime(date('Y-m-d 00:00:00',time()));        $count['today2'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),        ];        //前天        $star = strtotime("-2 day");        $end = strtotime("-1 day");        $count['today3'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            /*'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),*/        ];        //-4天        $star = strtotime("-3 day");        $end = strtotime("-2 day");        $count['today4'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            /*'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),*/        ];        //-5天        $star = strtotime("-4 day");        $end = strtotime("-3 day");        $count['today5'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            /*'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),*/        ];        //-6天        $star = strtotime("-5 day");        $end = strtotime("-4 day");        $count['today6'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            /*'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),*/        ];        //-7天        $star = strtotime("-6 day");        $end = strtotime("-5 day");        $count['today7'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            /*'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),*/        ];        //本月起至时间 - 月度统计         $end = mktime(0,0,0,date('m'),1,date('y'));         $count['month'] = [            'all' => self::where($filter)->where('create_time','>',$end)->count(),            'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$end)->count(),        ];        //上月开始          $star = mktime(0,0,0,date('m')-1,1,date('y'));         $count['month2'] = [            'all' => self::where($filter)->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'tang' => self::where($filter)->where(['order_mode'=> 10])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'wai' => self::where($filter)->where(['order_mode'=> 20])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'qu' => self::where($filter)->where(['order_mode'=> 30])->where('create_time','>',$star)->where('create_time','<',$end)->count(),            'refund' => self::where($filter)->where(['order_status' => 40])->where('create_time','>',$star)->where('create_time','<',$end)->count(),        ];        return $count;    }}